Instead of suppling a slot number to qemu-xen, supply a devfn.
This and subsequent other changes will allow xend to ask
for more than one function to be inserted into a single slot -
by specifying which function of the slot should be used.
This is a minimal patch for this change. A subsequent
patch that has a lot of noise to rename slot to devfn
is intended to follow.
Cc: Dexuan Cui <dexuan.cui@intel.com>
Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
from xen.util import utils
from xen.xend import uuid
from xen.xend import sxp
-from xen.xend.XendConstants import AUTO_PHP_SLOT
+from xen.xend.XendConstants import AUTO_PHP_DEVFN
from xen.xend.XendSXPDev import dev_dict_to_sxp
PROC_PCI_PATH = '/proc/bus/pci/devices'
# Definitions from Linux: include/linux/pci.h
def PCI_DEVFN(slot, func):
return ((((slot) & 0x1f) << 3) | ((func) & 0x07))
+def PCI_SLOT(devfn):
+ return (devfn >> 3) & 0x1f
+def PCI_FUNC(devfn):
+ return devfn & 0x7
def PCI_BDF(domain, bus, slot, func):
return (((domain & 0xffff) << 16) | ((bus & 0xff) << 8) |
out['slot'] = "0x%02x" % int(pci_dev_info['slot'], 16)
out['func'] = "0x%x" % int(pci_dev_info['func'], 16)
if pci_dev_info['vslot'] == '':
- vslot = AUTO_PHP_SLOT
+ vslot = AUTO_PHP_DEVFN
else:
- vslot = int(pci_dev_info['vslot'], 16)
+ vslot = PCI_DEVFN(int(pci_dev_info['vslot'], 16), 0)
out['vslot'] = "0x%02x" % vslot
if pci_dev_info['opts'] != '':
out['opts'] = split_pci_opts(pci_dev_info['opts'])
def parse_pci_name(pci_name_string):
pci = parse_pci_name_extended(pci_name_string)
- if int(pci['vslot'], 16) != AUTO_PHP_SLOT:
+ if int(pci['vslot'], 16) != AUTO_PHP_DEVFN:
raise PciDeviceParseError(("Failed to parse pci device: %s: " +
- "vslot provided where prohibited: %s") %
- (pci_name_string, pci['vslot']))
+ "vslot provided where prohibited: 0x%02x") %
+ (pci_name_string,
+ PCI_SLOT(int(pci['vslot'], 16))))
if 'opts' in pci:
raise PciDeviceParseError(("Failed to parse pci device: %s: " +
"options provided where prohibited: %s") %
from xen.xend.XendError import VmError
from xen.xend.XendDevices import XendDevices
from xen.xend.PrettyPrint import prettyprintstring
-from xen.xend.XendConstants import DOM_STATE_HALTED, AUTO_PHP_SLOT_STR
+from xen.xend.XendConstants import DOM_STATE_HALTED, AUTO_PHP_DEVFN_STR
from xen.xend.xenstore.xstransact import xstransact
from xen.xend.server.BlktapController import blktap_disk_types
from xen.xend.server.netif import randomMAC
'VM': self['uuid'],
'PPCI': ppci_uuid,
'hotplug_slot': pci_dev.get('vslot',
- '0x' + AUTO_PHP_SLOT_STR)
+ '0x' + AUTO_PHP_DEVFN_STR)
}
dpci_opts = pci_dev.get('opts')
XS_VMROOT = "/vm/"
+NR_PCI_FUNC = 8
NR_PCI_DEV = 32
-AUTO_PHP_SLOT = NR_PCI_DEV
-AUTO_PHP_SLOT_STR = "%02x" % NR_PCI_DEV
+NR_PCI_DEVFN = NR_PCI_FUNC * NR_PCI_DEV
+AUTO_PHP_DEVFN = NR_PCI_DEVFN
+AUTO_PHP_DEVFN_STR = "%02x" % NR_PCI_DEVFN
#
# tmem
pci_devs = pci_conf['devs']
for x in pci_devs:
if (int(x['vslot'], 16) == int(new_dev['vslot'], 16) and
- int(x['vslot'], 16) != AUTO_PHP_SLOT):
+ int(x['vslot'], 16) != AUTO_PHP_DEVFN):
raise VmError("vslot %s already have a device." % (new_dev['vslot']))
if (pci_dict_cmp(x, new_dev)):
slot = parse_hex(pci_config.get('slot', 0))
func = parse_hex(pci_config.get('func', 0))
vslot = parse_hex(pci_config.get('vslot',
- '0x' + AUTO_PHP_SLOT_STR))
+ '0x' + AUTO_PHP_DEVFN_STR))
if pci_config.has_key('opts'):
opts = serialise_pci_opts(pci_config['opts'])
has_vslot = False
for x in devs:
- if x['vslot'] == AUTO_PHP_SLOT:
+ if x['vslot'] == AUTO_PHP_DEVFN:
x['show_vslot'] = '-'
+ x['show_vfunc'] = '-'
else:
- x['show_vslot'] = "0x%02x" % x['vslot']
+ x['show_vslot'] = "0x%02x" % PCI_SLOT(x['vslot'])
+ x['show_vfunc'] = "0x%x" % PCI_FUNC(x['vslot'])
has_vslot = True
hdr_str = 'domain bus slot func'
fmt_str = '0x%(domain)04x 0x%(bus)02x 0x%(slot)02x 0x%(func)x'
if has_vslot:
- hdr_str = 'VSlt ' + hdr_str
- fmt_str = '%(show_vslot)-4s ' + fmt_str
+ hdr_str = 'VSlt VFn ' + hdr_str
+ fmt_str = '%(show_vslot)-4s %(show_vfunc)-3s ' + fmt_str
print hdr_str
for x in devs:
config_pci_opts)
if serverType == SERVER_XEN_API:
-
pci_dev = sxp.children(pci, 'dev')[0]
domain = int(sxp.child_value(pci_dev, 'domain'), 16)
bus = int(sxp.child_value(pci_dev, 'bus'), 16)